﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2012-12-28 17:01:58Z</CreationDate>
</File>
*/
#endregion

using System.Collections.Generic;
using System.Linq;

namespace Outcoder.UI.Xaml
{
	public class ListGrouping<TElement> : List<TElement>, IGrouping<object, TElement>
	{
		readonly object key;

		public ListGrouping(object key, IEnumerable<TElement> items)
		{
			this.key = ArgumentValidator.AssertNotNull(key, "key");
			AddRange(ArgumentValidator.AssertNotNull(items, "items"));
		}

		public object Key
		{
			get
			{
				return key;
			}
		}

		public bool HasItems
		{
			get
			{
				return this.Any();
			}
		}

		public override bool Equals(object obj)
		{
			var otherGrouping = obj as ListGrouping<TElement>;
			return otherGrouping != null && Key.Equals(otherGrouping.Key);
		}

		public override int GetHashCode()
		{
			return Key.GetHashCode();
		}
	}
}
